$(function(){
	var page = 1;
	var myName = localStorage.getItem("my_name");
	$("#message_w").click(function(){
		location.href = "send_private_massage.html";
	});
	$("#toleft").click(function(){
		window.history.back(-1);
	});
	$("#myName").text(myName);
	var $modal = $('#my-modal-loading');
	var query_id = localStorage.getItem("query_id");
	var uid = localStorage.getItem("person_id");
	var lookOverOtherCreatePublish = "http://yx.fxtourong.com/V1/Member/lookOverOtherCreatePublish" + "?store_id=" + query_id;
	getData();
	
	function getData(){
		$modal.modal();
		$.ajax({
			type: "POST",
			url: lookOverOtherCreatePublish,
			data: {
				uid : uid,
				page: page
			},
			dataType: "json",
			success: function(data) {
				$modal.modal('close');
				var code = data.code;
				console.log("code:" + data.code);
				if(code == "1") {
					isFirst = true;
					var jsonStr = data.data;
					for(var i = 0; i<jsonStr.length; i++){
						var industry = jsonStr[i];
						var timestr = industry.created_time.split(' ');
						var date = timestr[0];
						var hour = timestr[1];
						var typeStr = "语音";
						if(industry.g_type == "1"){
							typeStr = "语音";
						} else if(industry.g_type == "3") {
							typeStr = "文本";
						} else {
							typeStr = "图文";
						}
						var countimage = 0;
						if(typeStr == "图文"){
							countimage = industry.cover.length;
							for(var j = 0; j < countimage; j++){
								if(j == 0){
									image1 = industry.cover[j];
								} else if(j == 1){
									image2 = industry.cover[j];
								} else {
									image3 = industry.cover[j];
								}
							}
						} 
						if(typeStr == "语音"){
							var details = industry.details;
							if(details == "" || details == undefined || details == null){
								$(".timeline").append("<li>" + 
								"<span style='position: relative;top: 25px;left: 20px;font-size: 13px;'>" + date + "</span>" + 
    							"<span style='position: relative;top: 45px;left: -20px;font-size: 13px;'>" + hour + "</span>" +
										"<img src='../../public/yx/img/point.svg ' width='20 ' height='20 ' style='position: relative; top: 31px; left: 33px; '>" +
									"<div class='sendl ' style='position:relative; min-height: 30px; border-left: 2px solid #3a8abb; background:#fbfbfb; margin: -10px 20px 10px 95px; box-shadow: 10px 0px 20px -6px rgba(0, 0, 0, 0.1); '>" +
										"<p style='padding:20px 20px 5px 20px;margin: 0;font-size: 14px; '></p>" +
										"<img style='margin:0 0px 3px 20px; ' class='am- ' src='../../public/yx/img/yuyin_tiao.svg ' height='30 ' '>" + 
										"<br/><span style='font-size: 13px;margin: 0px auto;color: #999;padding: 0 0 20px 20px;display: inline-block;'>" + industry.circle_name + "</span>" + 
										"<div class='arrowl' style='position: absolute;top: 12px;left: -26px;width: 0;height: 0;font-size: 0;border: solid 12px;border-color: #F5F6F7 #3a8abb #F5F6F7 #F5F6F7;'>" + 
										"</div>" + 
									"</div>" + 
								"</li>");
							} else {
								$(".timeline").append("<li>" +
								"<span style='position: relative;top: 25px;left: 20px;font-size: 13px;'>" + date + "</span>" + 
    							"<span style='position: relative;top: 45px;left: -20px;font-size: 13px;'>" + hour + "</span>" +
								"<img src='../../public/yx/img/point.svg' width='20' height='20' style='position: relative;top: 31px;left: 33px;'>" + 
								"<div class='sendl' style='position:relative;min-height: 30px;border-left: 2px solid #3a8abb; background:#fbfbfb; margin: -10px 20px 10px 95px;box-shadow: 10px 0px 20px -6px rgba(0, 0, 0, 0.1);'>" + 
									"<p style='padding:20px 20px 5px 20px;margin: 0;font-size: 14px;'>"  + industry.details + "</p>" + 
									"<img style='margin:0 0px 3px 20px;' class='am-' src='../../public/yx/img/yuyin_tiao.svg' height='30' '>" + 
									"<br/><span style='font-size: 13px;margin: 0px auto;color: #999;padding: 0 0 20px 20px;display: inline-block; '>" + industry.circle_name + "</span>" + 
								"<div class='arrowl ' style='position: absolute; top: 12px; left: -26px;width: 0;height: 0;font-size: 0;border: solid 12px; border-color: #F5F6F7 #3a8abb #F5F6F7 #F5F6F7; '>" + 					
								"</div>" + 
								"</div>" + 
								"</li>");
							}
							
						} else if(typeStr == "文本") {
				      		$(".timeline").append("<li value='" + (((page-1) * 10) + i) + "' onclick=''>" + 
				      		"<span style='position: relative;top: 25px;left: 20px;font-size: 13px;'>" + date + "</span>" + 
    							"<span style='position: relative;top: 45px;left: -20px;font-size: 13px;'>" + hour + "</span>" +
								"<img src='../../public/yx/img/point.svg' width='20' height='20' style='position: relative;top: 31px;left: 33px;'>" + 
								"<div class='sendl' style='position:relative;min-height: 30px;border-left: 2px solid #3a8abb; background:#fbfbfb; margin: -10px 20px 10px 95px;box-shadow: 10px 0px 20px -6px rgba(0, 0, 0, 0.1);'>" + 
									"<p style='padding:20px 20px 5px 20px;margin: 0;font-size: 14px;'>" + industry.details + "</p>" + 
									"<span style='font-size: 13px;margin: 0px auto;color: #999;padding: 0 0 20px 20px;display: inline-block;'>" + industry.circle_name + "</span>" + 
									"<div class='arrowl' style='position: absolute;top: 12px;left: -26px;width: 0;height: 0;font-size: 0;border: solid 12px;border-color: #F5F6F7 #3a8abb #F5F6F7 #F5F6F7;'>" + 
									"</div>" + 
								"</div>" + 
							"</li>");
						} else {
							if(countimage == 1){
								$(".timeline").append("<li>" + 
								"<span style='position: relative;top: 25px;left: 20px;font-size: 13px;'>" + date + "</span>" + 
    							"<span style='position: relative;top: 45px;left: -20px;font-size: 13px;'>" + hour + "</span>" +
									"<img src='../../public/yx/img/point.svg' width='20' height='20' style='position: relative;top: 31px;left: 33px;'>" + 
									"<div class='sendl' style='position:relative;min-height: 30px;border-left: 2px solid #3a8abb; background:#fbfbfb; margin: -10px 20px 10px 95px;box-shadow: 10px 0px 20px -6px rgba(0, 0, 0, 0.1);'>" + 
										"<p style='padding:20px 20px 5px 20px;margin: 0;font-size: 14px;'>" + industry.details + "</p>" + 
										"<img style='margin:0 0px 3px 20px;' class='am-' src='" + image1 + "' width='30' height='30' '>" + "<br />" + 
										"<span style='font-size: 13px;margin: 0px auto;color: #999;padding: 0 0 20px 20px;display: inline-block; '>" + industry.circle_name + "</span>" +
									    "<div class='arrowl ' style='position: absolute; top: 12px; left: -26px;width: 0;height: 0;font-size: 0;border: solid 12px; border-color: #F5F6F7 #3a8abb #F5F6F7 #F5F6F7; '>" + 						
									"</div>" + 
									"</div>" +
									"</li>");
							} else if (countimage == 2){
								$(".timeline").append("<li>" + 
								"<span style='position: relative;top: 25px;left: 20px;font-size: 13px;'>" + date + "</span>" + 
    							"<span style='position: relative;top: 45px;left: -20px;font-size: 13px;'>" + hour + "</span>" +
									"<img src='../../public/yx/img/point.svg' width='20' height='20' style='position: relative;top: 31px;left: 33px;'>" + 
									"<div class='sendl' style='position:relative;min-height: 30px;border-left: 2px solid #3a8abb; background:#fbfbfb; margin: -10px 20px 10px 95px;box-shadow: 10px 0px 20px -6px rgba(0, 0, 0, 0.1);'>" + 
										"<p style='padding:20px 20px 5px 20px;margin: 0;font-size: 14px;'>" + industry.details + "</p>" + 
										"<img style='margin:0 0px 3px 20px;' class='am-' src='" + image1 + "' width='30' height='30' '>" + 
										"<img style='margin:0 0px 3px 10px; ' class='am- ' src='" + image2 + "' width='30 'height='30 ' '>" + "<br />" +  
										"<span style='font-size: 13px;margin: 0px auto;color: #999;padding: 0 0 20px 20px;display: inline-block; '>" + industry.circle_name + "</span>" +
									    "<div class='arrowl ' style='position: absolute; top: 12px; left: -26px;width: 0;height: 0;font-size: 0;border: solid 12px; border-color: #F5F6F7 #3a8abb #F5F6F7 #F5F6F7; '>" + 						
									"</div>" + 
									"</div>" +
									"</li>");
							} else {
					      		$(".timeline").append("<li>" + 
					      		"<span style='position: relative;top: 25px;left: 20px;font-size: 13px;'>" + date + "</span>" + 
    							"<span style='position: relative;top: 45px;left: -20px;font-size: 13px;'>" + hour + "</span>" +
									"<img src='../../public/yx/img/point.svg' width='20' height='20' style='position: relative;top: 31px;left: 33px;'>" + 
									"<div class='sendl' style='position:relative;min-height: 30px;border-left: 2px solid #3a8abb; background:#fbfbfb; margin: -10px 20px 10px 95px;box-shadow: 10px 0px 20px -6px rgba(0, 0, 0, 0.1);'>" + 
										"<p style='padding:20px 20px 5px 20px;margin: 0;font-size: 14px;'>" + industry.details + "</p>" + 
										"<img style='margin:0 0px 3px 20px;' class='am-' src='" + image1 + "' width='30' height='30' '>" + 
										"<img style='margin:0 0px 3px 10px; ' class='am- ' src='" + image2 + "' width='30 'height='30 ' '>" + 
										"<img style='margin:0 0px 3px 10px;' class='am-' src='" + image3 + "' width='30' height='30' '>" + "<br/>" + 
										"<span style='font-size: 13px;margin: 0px auto;color: #999;padding: 0 0 20px 20px;display: inline-block; '>" + industry.circle_name + "</span>" +
									    "<div class='arrowl ' style='position: absolute; top: 12px; left: -26px;width: 0;height: 0;font-size: 0;border: solid 12px; border-color: #F5F6F7 #3a8abb #F5F6F7 #F5F6F7; '>" + 						
									"</div>" + 
									"</div>" +
									"</li>");
							}
							
						}
						
					}
				} else {
					$modal.modal('close');
				}
			},
			error: function(e){
				$modal.modal('close');
				alert("服务请求异常！");
			}
		});
	}
	
	var isFirst = true;
	
	$(window).scroll(function() {
  
//	    if ($(document).scrollTop()<=0){
//	      alert("滚动条已经到达顶部为0");
//	    }
	  
	    if ($(document).scrollTop() >= ($(document).height() - $(window).height())) {
//	      	page = page + 1;
//			getData();
			if(isFirst){
				isFirst = false;
				page = page + 1;
				getData();
			}
			
	    }
  	});
	
	
});
